local skel = fk.CreateSkill{
  name = "kpaII__woqishi",
}

local KleeU = require "packages/klee_xy_I/utility/k_utility"

Fk:loadTranslationTable{
  ["kpaII__woqishi"] = "我!骑士",
  [":kpaII__woqishi"] = "出牌阶段，你可以将一张手牌当【决斗】使用；"..
  "目标角色可以取消之，然后其当前的手牌视为【闪】直到其回合结束。",

  ["#kpaII__woqishi"] = "我!骑士：你可以将一张手牌当【决斗】使用",
  ["#kpaII__woqishi2"] = "是否取消此【决斗】，然后令你当前的手牌视为【闪】直到回合结束。",
  ["@@kpaII__woqishi-inhand-turn"] = "我!骑士",

  ["$kpaII__woqishi1"] = "Knight of the woeful countenance.",
  ["$kpaII__woqishi2"] = "False graceless knight!",
}

skel:addEffect("viewas", {
  prompt = "#kpaII__woqishi",
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and table.contains(player:getHandlyIds(), to_select)
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("duel")
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local to = use.tos[1]
    local choose = KleeU.askYesOrNo(to, "#kpaII__woqishi2" ,skel.name)
    if choose then
      --
      for _,c in ipairs(to:getCardIds(Player.Hand)) do
        room:setCardMark(Fk:getCardById(c),"@@kpaII__woqishi-inhand-turn",1)
      end
      room:throwCard(use.card,skel.name,player,player)
      return "false"
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng()
  end
})

skel:addEffect("filter", {
  card_filter = function(self, to_select, player, isJudgeEvent)
    return to_select:getMark("@@kpaII__woqishi-inhand-turn") > 0
  end,
  view_as = function(self, card, to_select)
    return Fk:cloneCard("jink", to_select.suit, to_select.number)
  end,
})

return skel